const Koa = require('koa');
const router = require('koa-route');

const app = new Koa();

const logger = (ctx, next) => {
  console.log(`${ctx.url}--${ctx.method}--${new Date()}`);
  next();
};

const home = ctx => {
  ctx.body = '<h2>首页</h2>';
};

const about = ctx => {
  ctx.body = '<a href="/home"> 回到首页 </a>';
};

app.use(logger); // 中间件
app.use(router.get('/home', home));
app.use(router.get('/about', about));

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});
